//
//  ZuYueViewController.m
//  uplife
//
//  Created by ZhangCheng on 2018/12/26.
//  Copyright © 2018年 ZhangCheng. All rights reserved.
//

#import "ZuYueViewController.h"
#import "UIImageView+WebCache.h"

@interface ZuYueViewController ()
@property(nonatomic,strong)NSDictionary *dataDic;
@property (weak, nonatomic) IBOutlet UILabel *usernameLabel;
@property (weak, nonatomic) IBOutlet UILabel *nianLingLabel;
@property (weak, nonatomic) IBOutlet UILabel *xingBieLabel;
@property (weak, nonatomic) IBOutlet UILabel *jvZhuRenShuLabel;

@property (weak, nonatomic) IBOutlet UILabel *zuJinLabel;
@property (weak, nonatomic) IBOutlet UILabel *guanLiFeiLabel;
@property (weak, nonatomic) IBOutlet UILabel *liJinLabel;
@property (weak, nonatomic) IBOutlet UILabel *yaJinLabel;
@property (weak, nonatomic) IBOutlet UILabel *baoZhengJinLabel;
@property (weak, nonatomic) IBOutlet UILabel *baoXianGongSiLabel;
@property (weak, nonatomic) IBOutlet UILabel *baoZhengRenLabel;
@property (weak, nonatomic) IBOutlet UILabel *qiZuRiLabel;
@property (weak, nonatomic) IBOutlet UILabel *yueManRiLabel;
@property (weak, nonatomic) IBOutlet UILabel *mianZuQiLabel;
@property (weak, nonatomic) IBOutlet UIImageView *guangGaoImageView;

@end

@implementation ZuYueViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self sendRequestForLoadData];
}
-(void)sendRequestForLoadData{
    NSString *urlString = [NSString stringWithFormat:@"%@/realty/get-lease.do?roomId=%@&moneyTypeCode=%@",JSXF_HOST,self.roomId,[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"]];
    
    [SVProgressHUD show];
    
    [ZCWebServiceHelper requestWithMethod:GET andUrlStr:urlString andParameters:nil andFinished:^(id response, NSURLSessionDataTask *dataTask) {
        [SVProgressHUD dismiss];
        NSDictionary *dic = response;
        if ([dic[@"data"] isKindOfClass:[NSDictionary class]]) {
            self.dataDic = dic[@"data"];
            [self resetView];
        }
    }];
}

-(void)resetView{
    self.usernameLabel.text = [NSString stringWithFormat:@"%@",self.dataDic[@"inName"]];
    self.nianLingLabel.text = [NSString stringWithFormat:@"%@",self.dataDic[@"age"]];
    self.xingBieLabel.text = ((NSString*)self.dataDic[@"sex"]).integerValue==1?@"男":@"女";
    self.jvZhuRenShuLabel.text = [NSString stringWithFormat:@"%@",self.dataDic[@"inCount"]];
    
//    self.zuJinLabel.text = [NSString stringWithFormat:@"%@(%@%@)",self.dataDic[@"Jrent"],[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],self.dataDic[@"rent"]];
    self.zuJinLabel.text = [NSString stringWithFormat:@"%@",FORMAT_PRICE(self.dataDic[@"Jrent"])];
//    NSMutableAttributedString* string = [[NSMutableAttributedString alloc] initWithString:self.zuJinLabel.text attributes:@{NSFontAttributeName: self.zuJinLabel.font,NSForegroundColorAttributeName: self.zuJinLabel.textColor}];
//    [string addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:136/255.0 green:138/255.0 blue:143/255.0 alpha:1.0]} range:[self.zuJinLabel.text rangeOfString:[NSString stringWithFormat:@"(%@%@)",[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],self.dataDic[@"rent"]]]];
//    self.zuJinLabel.attributedText = string;
    
//    self.guanLiFeiLabel.text = [NSString stringWithFormat:@"%@(%@%@)",self.dataDic[@"JmanageCost"],[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],self.dataDic[@"manageCost"]];
    self.guanLiFeiLabel.text = [NSString stringWithFormat:@"%@",FORMAT_PRICE(self.dataDic[@"JmanageCost"])];
//    string = [[NSMutableAttributedString alloc] initWithString:self.guanLiFeiLabel.text attributes:@{NSFontAttributeName: self.guanLiFeiLabel.font,NSForegroundColorAttributeName: self.guanLiFeiLabel.textColor}];
//    [string addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:136/255.0 green:138/255.0 blue:143/255.0 alpha:1.0]} range:[self.guanLiFeiLabel.text rangeOfString:[NSString stringWithFormat:@"(%@%@)",[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],self.dataDic[@"manageCost"]]]];
//    self.guanLiFeiLabel.attributedText = string;
    
//    self.liJinLabel.text = [NSString stringWithFormat:@"%@(%@%@)",self.dataDic[@"JcashGift"],[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],self.dataDic[@"cashGift"]];
    self.liJinLabel.text = [NSString stringWithFormat:@"%@",FORMAT_PRICE(self.dataDic[@"JcashGift"])];
//    string = [[NSMutableAttributedString alloc] initWithString:self.liJinLabel.text attributes:@{NSFontAttributeName: self.liJinLabel.font,NSForegroundColorAttributeName: self.liJinLabel.textColor}];
//    [string addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:136/255.0 green:138/255.0 blue:143/255.0 alpha:1.0]} range:[self.liJinLabel.text rangeOfString:[NSString stringWithFormat:@"(%@%@)",[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],self.dataDic[@"cashGift"]]]];
//    self.liJinLabel.attributedText = string;
    
//    self.yaJinLabel.text = [NSString stringWithFormat:@"%@(%@%@)",self.dataDic[@"JcashCost"],[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],self.dataDic[@"cashCost"]];
    self.yaJinLabel.text = [NSString stringWithFormat:@"%@",FORMAT_PRICE(self.dataDic[@"JcashCost"])];
//    string = [[NSMutableAttributedString alloc] initWithString:self.yaJinLabel.text attributes:@{NSFontAttributeName: self.yaJinLabel.font,NSForegroundColorAttributeName: self.yaJinLabel.textColor}];
//    [string addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:136/255.0 green:138/255.0 blue:143/255.0 alpha:1.0]} range:[self.yaJinLabel.text rangeOfString:[NSString stringWithFormat:@"(%@%@)",[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],self.dataDic[@"cashCost"]]]];
//    self.yaJinLabel.attributedText = string;
    
//    self.baoZhengJinLabel.text = [NSString stringWithFormat:@"%@(%@%@)",self.dataDic[@"Jdeposit"],[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],self.dataDic[@"deposit"]];
    self.baoZhengJinLabel.text = [NSString stringWithFormat:@"%@",FORMAT_PRICE(self.dataDic[@"Jdeposit"])];
//    string = [[NSMutableAttributedString alloc] initWithString:self.baoZhengJinLabel.text attributes:@{NSFontAttributeName: self.baoZhengJinLabel.font,NSForegroundColorAttributeName: self.baoZhengJinLabel.textColor}];
//    [string addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:136/255.0 green:138/255.0 blue:143/255.0 alpha:1.0]} range:[self.baoZhengJinLabel.text rangeOfString:[NSString stringWithFormat:@"(%@%@)",[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],self.dataDic[@"deposit"]]]];
//    self.baoZhengJinLabel.attributedText = string;
    
    self.baoXianGongSiLabel.text = [NSString stringWithFormat:@"%@",self.dataDic[@"ensure"]];
    self.baoZhengRenLabel.text = [NSString stringWithFormat:@"%@",self.dataDic[@"voucher"]];
    self.qiZuRiLabel.text = [NSString stringWithFormat:@"%@",self.dataDic[@"startDate"]];
    self.yueManRiLabel.text = [NSString stringWithFormat:@"%@",self.dataDic[@"endDate"]];
    self.mianZuQiLabel.text = [NSString stringWithFormat:@"%@",self.dataDic[@"rentFree"]];
    if (self.mianZuQiLabel.text.length==0) {
        self.mianZuQiLabel.text = @"無";
    }
    if (((NSArray*)self.dataDic[@"ads"]).count==0) {
        self.guangGaoImageView.image = nil;
    }else{
        NSDictionary *dic = self.dataDic[@"ads"][0];
        [self.guangGaoImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",JSXF_HOST_FILE,dic[@"picturePath"]]]];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40.0f;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UITableViewHeaderFooterView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"headerView"];
    if (!headerView) {
        headerView = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:@"headerView"];
        [headerView setFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 40.0f)];
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15.0f, 15.0f, 100.0f, 14.0f)];
        titleLabel.tag = 1;
        [titleLabel setFont:[UIFont fontWithName:@"HiraginoSans-W6" size: 16]];
        [titleLabel setTextColor: [UIColor colorWithRed:184.0f/255.0 green:153.0f/255.0 blue:98.0f/255.0 alpha:1.0]];
        [headerView.contentView addSubview:titleLabel];
        [headerView.contentView setBackgroundColor:[UIColor clearColor]];
    }
    UILabel *titleLabel = [headerView viewWithTag:1];
    if (section==0) {
        [titleLabel setText:@"住户信息"];
    }else{
        [titleLabel setText:@"契约条件"];
    }
    return headerView;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
